﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MapInfo_DepartmentPassList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
            Bind1();
            Bind3();
            Bind4();
        }

        

    }

    private void Bind4()
    {
        if (Request["IsPass"] == null)
            return;
        string Where = string.Empty;
        string DepartmentID = string.Empty;
        if (Request["DepartmentID"] == null)
        {
            //Where = "And Right(Left(DepartmentID,5),1)='3' ";
            Where = "And Right(Left(DepartmentID,5),1)='3'  And DepartmentID Not In(Select DepartmentID From DepartmentKinds Where Right(Left(DepartmentID,5),1)='3')";
        }
        else
        {
            DepartmentID = Request["DepartmentID"];
            Where = "And Right(Left(DepartmentID,5),1)='3' And left(DepartmentID,4)='" + DepartmentID.Substring(0, 4) + "' And DepartmentID Not In(Select DepartmentID From DepartmentKinds Where Left(DepartmentID,4)='"+DepartmentID.Substring(0,4)+"')";
        }
        if (Request["IsPass"].Equals("1") || Request["IsPass"].Equals("0"))
        {
            List<Yipusoft.MapInfo.Model.DepartmentPassInfo> list = Yipusoft.MapInfo.BLL.DepartmentPass.GetList(" IsPass=" + Request["IsPass"] + "  " + Where);
            if (list == null)
                return;
            this.GridView4.DataSource = list;
            this.ListPageContral4.ItemCount = list.Count();
            GridView4.DataBind();
            if (Request["IsPass"].Equals("1"))
            {
                Label4.Text = "已达标县市中队列表";
            }
            else
            {
                Label4.Text = "未达标县市中队列表";
            }
        }
        
    }
    private void Bind3()
    {
        if (Request["IsPass"] == null)
            return;
        string Where = string.Empty;
        string DepartmentID = string.Empty;
        Where = " And Right(DepartmentID,2)='00'";
        if (Request["DepartmentID"] != null)
        {
            DepartmentID = Request["DepartmentID"];
            Where = " And DepartmentID='" + DepartmentID + "'";
        }    

        if (Request["IsPass"].Equals("1") || Request["IsPass"].Equals("0"))
        {
            List<Yipusoft.MapInfo.Model.DepartmentPassInfo> list = Yipusoft.MapInfo.BLL.DepartmentPass.GetList(" IsPass=" + Request["IsPass"] + "  " + Where);
            if (list == null)
                return;

            GridView2.DataSource = list;           
            GridView2.DataBind();
            if (Request["IsPass"].Equals("1"))
            {
               Label3.Text = "已达标支队列表";
            }
            else
            {
                Label3.Text = "未达标支队列表";
            }
        }
    }

   public void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        GvwList.PageIndex = PageIndex;

        Bind();
        


    }

   public void ListPageContral4_PageSizeChange(int pageSize, int PageIndex)
   {
       GridView4.PageIndex = PageIndex;

       Bind4();



   }
   public void ListPageContral2_PageSizeChange(int pageSize, int PageIndex)
   {
       GvwList1.PageIndex = PageIndex;
       Bind1();     

   }
    protected void GvwList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("lblID");
            ID.Text = ((ListPageContral1.CurrentPageIndex * ListPageContral1.PageSize) + (e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
    protected void GvwList1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("lblID");
            ID.Text = ((ListPageContral2.CurrentPageIndex * ListPageContral1.PageSize) + (e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
    protected void GvwList3_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("lblID");
            ID.Text = (e.Row.RowIndex + 1).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }

    protected void GvwList4_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("lblID");
            ID.Text = ((ListPageContral4.CurrentPageIndex * ListPageContral4.PageSize) + (e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
    //大队
    private void Bind()
    {
        if (Request["IsPass"] == null)
            return;
        string Where = string.Empty;
        string DepartmentID = string.Empty;
        if (Request["DepartmentID"] == null)
        {
            Where = "And Right(Left(DepartmentID,5),1)='2' ";
        }
        else
        {
            DepartmentID = Request["DepartmentID"];
            Where = "And Right(Left(DepartmentID,5),1)='2' And left(DepartmentID,4)='" + DepartmentID.Substring(0, 4) + "'";
        }
       
        if (Request["IsPass"].Equals("1") || Request["IsPass"].Equals("0"))
        {
            List<Yipusoft.MapInfo.Model.DepartmentPassInfo> list = Yipusoft.MapInfo.BLL.DepartmentPass.GetList(" IsPass=" + Request["IsPass"] + "  "+ Where);
            if (list == null)
                return;
            GvwList.DataSource = list;
            this.ListPageContral1.ItemCount = list.Count();
            GvwList.DataBind();
            if (Request["IsPass"].Equals("1"))
            {
                lblState.Text = "已达标大队列表";
            }
            else
            {
                lblState.Text = "未达标大队列表";
            }
        }

    
    }
    //中队
    private void Bind1()
    {
        if (Request["IsPass"] == null)
            return;
        string Where = string.Empty;
        string DepartmentID = string.Empty;
        if (Request["DepartmentID"] == null)
        {
            //Where = "And Right(Left(DepartmentID,5),1)='3' ";
            Where = "And Right(Left(DepartmentID,5),1)='3'  And DepartmentID  In(Select DepartmentID From DepartmentKinds Where Right(Left(DepartmentID,5),1)='3')";
        }
        else
        {
            DepartmentID = Request["DepartmentID"];
            //Where = "And Right(Left(DepartmentID,5),1)='3' And left(DepartmentID,4)='" + DepartmentID.Substring(0, 4) + "'";
            Where = "And Right(Left(DepartmentID,5),1)='3' And left(DepartmentID,4)='" + DepartmentID.Substring(0, 4) + "' And DepartmentID In(Select DepartmentID From DepartmentKinds Where Left(DepartmentID,4)='" + DepartmentID.Substring(0, 4) + "')";
        }
        if (Request["IsPass"].Equals("1") || Request["IsPass"].Equals("0"))
        {
            List<Yipusoft.MapInfo.Model.DepartmentPassInfo> list = Yipusoft.MapInfo.BLL.DepartmentPass.GetList(" IsPass=" + Request["IsPass"] + "  " + Where);
            if (list == null)
                return;
            GvwList1.DataSource = list;
            this.ListPageContral2.ItemCount = list.Count();
            GvwList1.DataBind();
            if (Request["IsPass"].Equals("1"))
            {
                Label2.Text = "已达标市区中队列表";
            }
            else
            {
                Label2.Text = "未达标市区中队列表";
            }
        }


    }



    //支队
    protected void LinkButton1_Command1(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;
        SetIsPass(false, e.CommandArgument.ToString());
        Bind3();
    }
    protected void BtnID_Command1(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;

        SetIsPass(true, e.CommandArgument.ToString());
        Bind3();

    }

    //中队
    protected void LinkButton1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;
        SetIsPass(false, e.CommandArgument.ToString());
        Bind1();

    }
    protected void BtnID_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;

        SetIsPass(true, e.CommandArgument.ToString());
        Bind1();


    }
    //中队
    protected void LinkButton1_Command4(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;
        SetIsPass(false, e.CommandArgument.ToString());
        Bind4();

    }
    protected void BtnID_Command4(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;

        SetIsPass(true, e.CommandArgument.ToString());
        Bind4();


    }

    private void SetIsPass(bool Flag,string ID)
    {

        List<Yipusoft.MapInfo.Model.DepartmentPassInfo> list = Yipusoft.MapInfo.BLL.DepartmentPass.GetList("  ID=" + ID + "");
        if (list == null || list.Count() <= 0)
            return;

        Yipusoft.MapInfo.Model.DepartmentPassInfo info = list[0];
        info.IsPass = Flag;

        Yipusoft.MapInfo.BLL.DepartmentPass.Update(info);     
        
    }

    public bool IsTrue()
    {
        return Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "500001");
    }
    protected void BtnID_Command3(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;

        SetIsPass(true, e.CommandArgument.ToString());
        Bind();
    }
    protected void LinkButton1_Command3(object sender, CommandEventArgs e)
    {
        if (e.CommandArgument == null)
            return;

        SetIsPass(false, e.CommandArgument.ToString());
        Bind();
    }
}
